@extends('Admin.Layouts.index')

@section('content')
    <script type="text/javascript" src="{{asset('admin/js/jquery.js')}}"></script>
<script type="text/javascript" src="{{asset('layer/layer.js')}}"></script>
<div class="box-content">
    <div >
        <form action="{{url('admin/users')}}" method="get">
        <div class="row-fluid">
            <div id="DataTables_Table_1_length" class="dataTables_length">
            <label>显示 
                <select size="1" name="count">
                    <option value="10" @if(!empty($req['count']) && $req['count'] == 10) selected @endif>10</option>
                    <option value="20" @if(!empty($req['count']) && $req['count'] == 20) selected @endif>20</option>
                    <option value="30" @if(!empty($req['count']) && $req['count'] == 30) selected @endif>30</option>
                    <option value="50" @if(!empty($req['count']) && $req['count'] == 50) selected @endif>50</option>
                </select>条
            </label>            </div>
            <div class="span6" style="float:right;margin-top:-50px;margin-right: -180px; ">
                <div class="dataTables_filter" id="DataTables_Table_0_filter">
                    <label>
                        
                            <font style="vertical-align: inherit;">
                                <font style="vertical-align: inherit;">
                                </font>
                            </font>
                        <input type="text" style="height: 27px;margin-top:10px;" name="keywords" aria-controls="DataTables_Table_0" value="{{$input}}">
                        <input type="submit" class="btn-info btn-xm" value="搜索">  
                  </label>
                </div>
            </div>
        </div>
        </form>
        <table class="table table-striped table-bordered bootstrap-datatable datatable dataTable"
        id="DataTables_Table_0" aria-describedby="DataTables_Table_0_info">
         <div class="box-header" data-original-title="">
            <h2><i class="halflings-icon white user"></i><span class="break"></span><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">用户列表</font></font></h2>
            <div class="box-icon">
                <a href="#" class="btn-setting"><i class="halflings-icon white wrench"></i></a>
                <a href="#" class="btn-minimize"><i class="halflings-icon white chevron-up"></i></a>
                <a href="#" class="btn-close"><i class="halflings-icon white remove"></i></a>
            </div>
         </div>
            <tr role="row">
                <th class="sorting_asc" role="columnheader" tabindex="0" aria-controls="DataTables_Table_0"
                rowspan="1" colspan="1" aria-sort="ascending" aria-label="Username: activate to sort column descending"
                style="width: 129px;">
                    <font style="vertical-align: inherit;">
                        <font style="vertical-align: inherit;">
                            ID
                        </font>
                    </font>
                </th>
                <th class="sorting_asc" role="columnheader" tabindex="0" aria-controls="DataTables_Table_0"
                rowspan="1" colspan="1" aria-sort="ascending" aria-label="Username: activate to sort column descending"
                style="width: 129px;">
                    <font style="vertical-align: inherit;">
                        <font style="vertical-align: inherit;">
                            用户名
                        </font>
                    </font>
                </th>
                <th class="sorting" role="columnheader" tabindex="0" aria-controls="DataTables_Table_0"
                rowspan="1" colspan="1" aria-label="Date registered: activate to sort column ascending"
                style="width: 191px;">
                    <font style="vertical-align: inherit;">
                        <font style="vertical-align: inherit;">
                            密码
                        </font>
                    </font>
                </th>

                <th class="sorting" role="columnheader" tabindex="0" aria-controls="DataTables_Table_0"
                rowspan="1" colspan="1" aria-label="Actions: activate to sort column ascending"
                style="width: 224px;">
                    <font style="vertical-align: inherit;">
                        <font style="vertical-align: inherit;">
                            操作
                        </font>
                    </font>
                </th>
            </tr>
                @foreach($user as $k=>$v)
                <tr class="odd">
                    <td class=" sorting_1">
                        <font style="vertical-align: inherit;">
                            <font style="vertical-align: inherit;">
                                {{$v->id}}
                            </font>
                        </font>
                    </td>
                    <td class="center ">
                        <font style="vertical-align: inherit;">
                            <font style="vertical-align: inherit;">
                                {{$v->username}}
                            </font>
                        </font>
                    </td>
                     <td class="center " style="width: 200px;display: block;overflow: hidden;">
                        <font style="vertical-align: inherit;">
                            <font style="vertical-align: inherit;">
                                {{$v->password}}
                            </font>
                        </font>
                    </td>

                    <td class="center ">
                        <form action="{{url('admin/users/'.$v->id.'/edit')}}" method="get" style="display: inline;">
                            {{ csrf_field() }}
                            <input type="submit" value="修改" class="btn btn-info" style="width:40px;height: 30px;text-align:center;padding:0;">
                        </form>
                            <a href="javascript:;" onclick="delUser({{$v->id}})" class="btn btn-warning" style="width:40px;height: 30px;text-align:center;padding:0;">删除</a>

                    </td>
                </tr>
            @endforeach
        </table>
                         <div class="pagination pagination-centered">
                           {!! $user->appends(['keywords'=>$input])->render() !!}
                        </div> 

    </div>
</div>
<script>
    
        function delUser(userid){

           layer.confirm('确认删除吗？', {
                btn: ['确定','取消'] //按钮
            }, function(){
                //向服务器发送删除请求
//                $.ajax(请求的路径，携带的参数，返回的结果)
//                url===>admin/user/21
                $.post("{{url('admin/users/')}}/ "+userid,{'_token':'{{csrf_token()}}','_method':'delete'},function(data){
                       if( data.status == 0){
//                            将json格式的字符串变成json对象
//                           var data = JSON.parse(data);
                           layer.msg(data.msg, {icon: 6});
                           location.href = location.href;
                       }else{
                           layer.msg(data.msg, {icon: 5});
                           location.href = location.href;
                       }
                });
                //
            }, function(){

            });
        }
</script>
@endsection